<?php

namespace Gds\VenteBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Gds\VenteBundle\Entity\ReglementClient
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Gds\VenteBundle\Entity\ReglementClientRepository")
 */
class ReglementClient
{
    /**
     * @ORM\ManyToOne(targetEntity="Gds\VenteBundle\Entity\Client", inversedBy="reglements")
     * @ORM\JoinColumn(nullable=false)
     */
    private $client;
     /**
     * @ORM\ManyToOne(targetEntity="Gds\VenteBundle\Entity\SessionCaisse", inversedBy="reglements")
     * @ORM\JoinColumn(nullable=false)
     */
    private $sessionCaisse;
     /**
     * @ORM\OneToMany(targetEntity="Gds\VenteBundle\Entity\LigneReglementClient", mappedBy="reglement",cascade={"persist"})
     */
    private $lignes; // Ici commentaires prend un "s", car un article a plusieurs commentaires !
   
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var \DateTime $date
     *
     * @ORM\Column(name="date", type="date")
     */
    private $date;

    /**
     * @var string $reference
     *
     * @ORM\Column(name="reference", type="string", length=255)
     */
    private $reference;

    /**
     * @var float $montant_ttc
     *
     * @ORM\Column(name="montant_ttc", type="decimal", scale=3)
     */
    private $montant_ttc;
 /**
     * @var integer
     *
     * @ORM\Column(name="heure", type="integer")
     */
    private $heure;
     /**
     * @var boolean $is_cloturer
     *
     * @ORM\Column(name="is_cloturer", type="boolean")
     */
    private $is_cloturer;
    /**
     * @var boolean $is_supprimer
     *
     * @ORM\Column(name="is_supprimer", type="boolean")
     */
    private $is_supprimer;
    /**
     * @ORM\ManyToOne(targetEntity="Gds\UserBundle\Entity\User", inversedBy="reglements_client")
     * @ORM\JoinColumn(nullable=false)
     */
    private $user;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     * @return ReglementClient
     */
    public function setDate($date)
    {
        $this->date = $date;
    
        return $this;
    }

    /**
     * Get date
     *
     * @return \DateTime 
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * Set reference
     *
     * @param string $reference
     * @return ReglementClient
     */
    public function setReference($reference)
    {
        $this->reference = $reference;
    
        return $this;
    }

    /**
     * Get reference
     *
     * @return string 
     */
    public function getReference()
    {
        return $this->reference;
    }

    /**
     * Set montant_ttc
     *
     * @param float $montantTtc
     * @return ReglementClient
     */
    public function setMontantTtc($montantTtc)
    {
        $this->montant_ttc = $montantTtc;
    
        return $this;
    }

    /**
     * Get montant_ttc
     *
     * @return float 
     */
    public function getMontantTtc()
    {
        return $this->montant_ttc;
    }
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->lignes = new \Doctrine\Common\Collections\ArrayCollection();
        $this->is_cloturer=FALSE;
        $this->is_supprimer=false;
    }
    
    /**
     * Add lignes
     *
     * @param Gds\VenteBundle\Entity\LigneReglementClient $lignes
     * @return ReglementClient
     */
    public function addLigne(\Gds\VenteBundle\Entity\LigneReglementClient $lignes)
    {
        $this->lignes[] = $lignes;
        $lignes->setReglement($this);
        return $this;
    }

    /**
     * Remove lignes
     *
     * @param Gds\VenteBundle\Entity\LigneReglementClient $lignes
     */
    public function removeLigne(\Gds\VenteBundle\Entity\LigneReglementClient $lignes)
    {
        $this->lignes->removeElement($lignes);
    }

    /**
     * Get lignes
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getLignes()
    {
        return $this->lignes;
    }

    /**
     * Set client
     *
     * @param \Gds\VenteBundle\Entity\Client $client
     * @return ReglementClient
     */
    public function setClient(\Gds\VenteBundle\Entity\Client $client)
    {
        $this->client = $client;

        return $this;
    }

    /**
     * Get client
     *
     * @return \Gds\VenteBundle\Entity\Client 
     */
    public function getClient()
    {
        return $this->client;
    }

    /**
     * Set heure
     *
     * @param integer $heure
     * @return ReglementClient
     */
    public function setHeure($heure)
    {
        $this->heure = $heure;

        return $this;
    }

    /**
     * Get heure
     *
     * @return integer 
     */
    public function getHeure()
    {
        return $this->heure;
    }

    /**
     * Set is_cloturer
     *
     * @param boolean $isCloturer
     * @return ReglementClient
     */
    public function setIsCloturer($isCloturer)
    {
        $this->is_cloturer = $isCloturer;

        return $this;
    }

    /**
     * Get is_cloturer
     *
     * @return boolean 
     */
    public function getIsCloturer()
    {
        return $this->is_cloturer;
    }

    /**
     * Set is_supprimer
     *
     * @param boolean $isSupprimer
     * @return ReglementClient
     */
    public function setIsSupprimer($isSupprimer)
    {
        $this->is_supprimer = $isSupprimer;

        return $this;
    }

    /**
     * Get is_supprimer
     *
     * @return boolean 
     */
    public function getIsSupprimer()
    {
        return $this->is_supprimer;
    }

    /**
     * Set user
     *
     * @param \Gds\UserBundle\Entity\User $user
     * @return ReglementClient
     */
    public function setUser(\Gds\UserBundle\Entity\User $user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \Gds\UserBundle\Entity\User 
     */
    public function getUser()
    {
        return $this->user;
    }
     public function getTime() {
        $time = $this->getHeure();
        $sec = $time % 60;
        if ($sec < 10)
            $sec = '0' . $sec;
        $reste = (int) ($time / 60);
        $minute = $reste % 60;
        if ($minute < 10)
            $minute = '0' . $minute;
        $heure = (int) ($reste / 60);
        if ($heure < 10)
            $heure = '0' . $heure;
        $res = $heure . ':' . $minute . ':' . $sec;
        return $res;
    }
    public function canModif() {
         return !$this->is_cloturer;
    }

    /**
     * Set sessionCaisse
     *
     * @param \Gds\VenteBundle\Entity\SessionCaisse $sessionCaisse
     * @return ReglementClient
     */
    public function setSessionCaisse(\Gds\VenteBundle\Entity\SessionCaisse $sessionCaisse)
    {
        $this->sessionCaisse = $sessionCaisse;

        return $this;
    }

    /**
     * Get sessionCaisse
     *
     * @return \Gds\VenteBundle\Entity\SessionCaisse 
     */
    public function getSessionCaisse()
    {
        return $this->sessionCaisse;
    }
}
